package com.smartlink.service;

import com.smartlink.dao.AdminDao;
import com.smartlink.pojo.AdminUser;
import com.smartlink.util.EmailUtil;

public class AdminService {
	private AdminDao adminDao;
	private EmailUtil emailUtil;

	public boolean login(String email, String password) {
		AdminUser amUser = adminDao.findByEmail(email);
		if (amUser != null) {
			if (password.equals(amUser.getPassword())) {
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}

	}

	/**
	 * 发送验证码电子邮件
	 * 如果用户不存在 返回false
	 * @param email
	 * @param identifiCode
	 * @return
	 */
	public boolean sendEmail(String email, int identifiCode) {
		AdminUser amUser = adminDao.findByEmail(email);
		if (amUser != null) {
			try {
				emailUtil.sendEmail(email, identifiCode);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return true;
		}
		return false;

	}

	public AdminDao getAdminDao() {
		return adminDao;
	}

	public void setAdminDao(AdminDao adminDao) {
		this.adminDao = adminDao;
	}

	public EmailUtil getEmailUtil() {
		return emailUtil;
	}

	public void setEmailUtil(EmailUtil emailUtil) {
		this.emailUtil = emailUtil;
	}

}
